//
//  ZYSearchView.swift
//  WeiBo
//
//  Created by zhangyu on 16/9/20.
//  Copyright © 2016年 zhangyu. All rights reserved.
//

import UIKit

class ZYSearchView: UIView {

@IBOutlet weak var searchTextFieldRightConstraint: NSLayoutConstraint!
@IBOutlet weak var searchButton: UIButton!
    
@IBOutlet weak var searchTextField: UITextField!
    
@IBAction func editBeginAction(_ sender: AnyObject) {
        
        searchTextFieldRightConstraint.constant = searchButton.width
        
        UIView.animate(withDuration: 0.3) {
            self.layoutIfNeeded()
        }
        
        
    }
    
    @IBAction func searchButtonAction(_ sender: AnyObject) {
        //  失去第一响应者
        searchTextField.resignFirstResponder()
        searchTextFieldRightConstraint.constant = 0
        UIView.animate(withDuration: 0.3) {
            self.layoutIfNeeded()
        }
        
        
        
    }
    //  使用类方法创建xib对象
    class func searchView() -> ZYSearchView {
        
        return UINib(nibName: "ZYSearchView", bundle: nil).instantiate(withOwner: nil, options: nil).last! as! ZYSearchView
    }
        override func awakeFromNib() {
            searchTextField.layer.borderColor = UIColor.red.cgColor
            searchTextField.layer.borderWidth = 2
            searchTextField.layer.cornerRadius = 5
            searchTextField.layer.masksToBounds = true
        }


}
